package logic

import (
	"context"
	"zero_demo06_rpc_api/user/api/internal/svc"
	"zero_demo06_rpc_api/user/api/internal/types"
	"zero_demo06_rpc_api/user/rpc/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
	return &CreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateLogic) Create(req *types.CreateRequest) (resp *types.CreateResponse, err error) {
	// todo: add your logic here and delete this line
	createUser, err := l.svcCtx.UserRpc.CreateUser(l.ctx, &user.UserCreateRequest{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		return nil, err
	}
	return &types.CreateResponse{
		Message: createUser.Message,
	}, nil
}
